

jQuery(function ($) {
    var user_info = JSON.parse(localStorage.getItem('user_info'));
    if (!user_info) {
        window.location.href = "/login/login.html";
    }
    var url = window.location.search;
    var valuesKey = url.split("=")[0];
    var values = url.split("=")[1];
    var param;
    if (valuesKey == '?order_sn') {
        param={
            orderId:'',
            orderSn:'values'
        }
    } else {
        param={
            orderId:values,
            orderSn:''
        }
    };
    var goodsAll = [];
    send_ajax('get', '/api/order/orderDetails', param, function (data) {
        var html = "";
        if (data.code == 200) {
            var data = data.data;
            var orderSn = data.order_sn;
            var orderId = data.id;
            var orderStatus = data.order_status;
            var paid_status = data.paid_status;
            var totalAmt = data.total_amt;
            $('#order_sn').html(orderSn);
            if (paid_status == 0) {
                $('.btn_pay').text('去付款');
                $('#order_status').text('未支付');
                $('.right').show();
            } else{
                $('.right').hide(); 
                if (orderStatus== 1) {
                    $('#order_status').text('待发货');
                } else if (orderStatus == 2) {
                    $('#order_status').text('待收货');
                } else if (orderStatus == 3) {
                    $('#order_status').text('已取消');
                } else if (orderStatus == 5) {
                    $('#order_status').text('已收货');
                } else if (orderStatus == 6) {
                    $('#order_status').text('已完成');
                }else if (orderStatus == 7) {
                    $('#order_status').text('退货中');
                }else if (orderStatus == 6) {
                    $('#order_status').text('退货完成');
                }
            }
           
            $('#order_p').text('￥' + keepTwoDecimalFull(totalAmt));
            $('#pay_type').text('在线支付');

            html+='<div class=\ "details_msg\">\
            <ul class=\ "order_addrs\">\
                <li class=\ "item\">\
                    <ul class=\ "list list_f list\">\
                        <li> <strong> 收货人信息</strong>\</li>\
                        <li>\u6536\u8D27\u4EBA\uFF1A'+ data.receiver + '</li>\
                        <li>\u5730\u5740\uFF1A' + ((data.province?data.province:'') +( data.city?data.city:'')+ (data.district?data.district:'') +( data.location?data.location:'')) + '</li>\
                        <li>\u624B\u673A\u53F7\u7801\uFF1A' + data.phone.substr(0, 3) + "****" + data.phone.substr(7) + '</li>\
                    </ul>\
                </li>\
                <li class="item '+ (data.logisticsCode ? 'open' : 'hide') +'">\
                    <ul class="list_t list">\
                        <li><strong>\u914D\u9001\u4FE1\u606F</strong> \</li>\
                        <li>\u914D\u9001\u65B9\u5F0F\uFF1A ' + (data.logisticsCode ? data.logisticsName : "")+'\u5FEB\u9012</li>\
                        <li class=\ "check\"><a href=\ "/user/logistics_inquiry.html?Logistics='+ (data.logisticsCode ? data.logisticsCode : "") + '&&delivery_sn=' + data.order_sn + '\" target=\ "_blank\">\u67E5\u770B\u7269\u6D41</a> </li>\
                    </ul>\
                </li>\
            </ul>\
        </div>'

        $('.details_content').html(html);
            var goodsList = data.goodsList;
            //渲染订单列表
            // var goodsAll = [];
            // joint_address(orderDelivery[0]);
            var goodsHtml='';
            // for(var m = 0;m<goodsList.length;m++){
                // var goodsList = goodsList[m].orderGoods;
                goodsHtml+='  <ul class=\"goods_head\">\
                                    <li>\u5546\u54C1</li>\
                                    <li>价格</li>\
                                    <li>购买数量</li>\
                                    <li>状态</li>\
                                </ul>\
                                <ul class=\ "detailsGoods\">'
                for(var k = 0;k<goodsList.length;k++){
                    var a_goods = goodsList[k];
                    goodsHtml+='<li class=\ "goods_item\">\
                                    <div class=\ "goods_msg\">\
                                        <div class=\ "item\">\
                                            <a href=\ "/goods-'+a_goods.id+ '.html\" target=\ "_blank\">\
                                                <img src=\ "' + (a_goods.thumb ? isImgHttp(a_goods.thumb) : '/asset/image/tu4.jpg') + '\" alt=\ "\" class=\ "pic\">\
                                            </a>\
                                            <a href=\ "/goods-'+a_goods.id+ '.html\" target=\ "_blank\"> <span>' + a_goods.goodsName + '</span></a>\
                                        </div>\
                                        <div class=\ "item\">\n ￥' + a_goods.goods_price +'/'+(a_goods.unitName?a_goods.unitName:'')+ '\n</div>\
                                        <div class=\ "item\">' +( a_goods.qty?a_goods.qty:1) + '\n</div>\
                                        <div class="item">\
                                            <span class="'+(paid_status==0?'open':'hide')+'">未支付</span>\
                                            <span class="'+(paid_status!=0&&orderStatus==1?'open':'hide')+'">待发货</span>\
                                            <span class="'+(paid_status!=0&&orderStatus==2?'open':'hide')+'">待发货</span>\
                                            <span class="'+(paid_status!=0&&orderStatus==3?'open':'hide')+'">已取消</span>\
                                            <span class="'+(paid_status!=0&&orderStatus==5?'open':'hide')+'">已收货</span>\
                                            <span class="'+(paid_status!=0&&orderStatus==6?'open':'hide')+'">已完成</span>\
                                            <span class="'+(paid_status!=0&&orderStatus==7?'open':'hide')+'">退货中</span>\
                                            <span class="'+(paid_status!=0&&orderStatus==8?'open':'hide')+'">退货完成/span>\
                                        </div>\
                                    </div>\
                                </li>'
                }

                goodsHtml+='</ul>'   

                // }
                $('.order_goods').html(goodsHtml)
          

            $('.btn_pay').click(function () {
                window.location.href = "/goods/order_payment.html?order=" + orderId;
            });
        }
    });
    //拼接购物地址
    var html='';
    function joint_address(address) {
        var addr = address.orderDelivery;
        var area_ids = {
            "Area[]": {
                "count": 10,
                "Area": {
                    "use_flag": 1,
                    "id{}": [addr.province, addr.city, addr.district, addr.street]
                }
            }
        };
        send_ajax('post', '/get', area_ids, function callback(data) {
            if (data.code == 200&&data["Area[]"]) {
                //修改主数据
                var addr_info = data["Area[]"];
                addr.province_obj = addr_info[0];
                addr.city_obj = addr_info[1];
                addr.district_obj = addr_info[2];
                addr.street_obj = addr_info[3];
            };
            html+='<div class=\ "details_msg\">\
                    <ul class=\ "order_addrs\">\
                        <li class=\ "item\">\
                            <ul class=\ "list list_f list\">\
                                <li> <strong> 收货人信息</strong>\</li>\
                                <li>\u6536\u8D27\u4EBA\uFF1A'+ addr.receiver + '</li>\
                                <li>\u5730\u5740\uFF1A' + (addr.province + addr.city_obj.name + addr.district_obj.name + addr.location) + '</li>\
                                <li>\u624B\u673A\u53F7\u7801\uFF1A' + addr.phone.substr(0, 3) + "****" + addr.phone.substr(7) + '</li>\
                            </ul>\
                        </li>\
                        <li class="item '+ (addr.logisticsCode ? 'open' : 'hide') +'">\
                            <ul class="list_t list">\
                                <li><strong>\u914D\u9001\u4FE1\u606F</strong> \</li>\
                                <li>\u914D\u9001\u65B9\u5F0F\uFF1A ' + (addr.logisticsCode ? addr.logisticsName : "")+'\u5FEB\u9012</li>\
                                <li class=\ "check\"><a href=\ "/user/logistics_inquiry.html?Logistics='+ (addr.logisticsCode ? addr.logisticsCode : "") + '&&delivery_sn=' + addr.delivery_sn + '\" target=\ "_blank\">\u67E5\u770B\u7269\u6D41</a> </li>\
                            </ul>\
                        </li>\
                    </ul>\
                </div>'

                $('.details_content').html(html);


            // $('.details_content').append("<div class=\"details_msg\">\n                        <ul class=\"order_addrs\">\n                            <li class=\"item\">\n                                <ul class=\"list list_f list\">\n                                    <li> <strong> \u6536\u8D27\u4EBA\u4FE1\u606F\uFF08" + parseInt(n + 1) + "\uFF09 </strong> </li>\n                                    <li>\u6536\u8D27\u4EBA\uFF1A" + address.receiver + "</li>\n                                    <li>\u5730\u5740\uFF1A" + (address.province_obj.name + address.city_obj.name + address.district_obj.name + address.location) + "</li>\n                                    <li>\u624B\u673A\u53F7\u7801\uFF1A" + address.phone.substr(0, 3) + "****" + address.phone.substr(7) + " </li>\n                                </ul>\n                            </li>\n                            <li class=\"item " + (Logistics ? 'open' : 'hide') + "\">\n                                <ul class=\"list_t list\">\n                                    <li> <strong>\u914D\u9001\u4FE1\u606F</strong> </li>\n                                    <li>\u914D\u9001\u65B9\u5F0F\uFF1A " + (Logistics ? Logistics.name : "") + "\u5FEB\u9012</li>\n                                    <li class=\"check\"> <a href=\"/user/logistics_inquiry.html?Logistics=" + (Logistics ? Logistics.code : "") + "&&delivery_sn=" + address.delivery_sn + "\" target=\"_blank\">\u67E5\u770B\u7269\u6D41</a></li>\n                                </ul>\n                            </li>\n                        </ul>\n                        <div class=\"order_goods\">\n                            <ul class=\"goods_head\">\n                                <li>\u5546\u54C1</li>\n                                <li>\u6613\u4ECE\u4EF7</li>\n                                <li>\u6570\u91CF</li>\n                                <li>\u5C0F\u8BA1</li>\n                            </ul>\n                            <ul data-delivery-id=\"" + address.id + "\" class=\"detailsGoods\">\n                            </ul>\n                        </div>\n                    </div> ");
            // if ($('.order_goods .detailsGoods').length == orderDelivery.length) {
            //     goods_html($('.detailsGoods'));
            // }
        });
    };
});